package com.ossjk.qlh.order.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ossjk.core.base.controller.BaseController;
import com.ossjk.core.util.CommonUtil;
import com.ossjk.core.vo.RequestBean;
import com.ossjk.core.vo.ResponseBean;
import com.ossjk.qlh.dishes.entity.Dishes;
import com.ossjk.qlh.dishes.service.IDishesService;
import com.ossjk.qlh.order.entity.Orderitm;
import com.ossjk.qlh.order.service.IOrderitmService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.Serializable;
import java.util.List;

/**
 *
 * 订单套餐项
 * @author liuxi
 * @since 2020-08-14
 */
@Api(tags = "订单套餐项")
@RestController
@RequestMapping("/order/orderitm")
public class OrderitmController extends BaseController {

	@Autowired
	private IOrderitmService iOrderitmService;

	@ApiOperation(value = "列表")
	@RequiresPermissions("00200010")
	@PostMapping("/list")
	public ResponseBean<Page<Orderitm>> list(@RequestBody RequestBean requestBean) {
		QueryWrapper<Orderitm> queryWrapper = new QueryWrapper<Orderitm>();
		return responseSuccess(iOrderitmService.page(requestBean.getPage(),queryWrapper));
	}

	@ApiOperation(value = "去修改")
	@RequiresPermissions("002000100010")
	@PostMapping("/toUpdate")
	public ResponseBean<Orderitm> toUpdate(@RequestBody RequestBean requestBean) {
		Orderitm orderitm = iOrderitmService.getById((Serializable) requestBean.getParam().get("id"));
		if (!CommonUtil.isBlank(orderitm)) {
			return responseSuccess(orderitm);
		} else {
			return responseFail();
		}
	}

	@ApiOperation(value = "添加")
	@RequiresPermissions("002000100000")
	@ApiOperationSupport(ignoreParameters = { "id", "crer", "mder", "crtm", "mdtm" })
	@PostMapping("/save")
	public ResponseBean save(@RequestBody RequestBean<Orderitm> requestBean) {
		if (iOrderitmService.save(requestBean.getData())) {
			return responseSuccess();
		} else {
			return responseFail();
		}
	}

	@ApiOperation(value = "修改")
	@RequiresPermissions("002000100010")
	@ApiOperationSupport(ignoreParameters = { "crer", "mder", "crtm", "mdtm" })
	@PostMapping("/update")
	public ResponseBean update(@RequestBody RequestBean<Orderitm> requestBean) {
		if (iOrderitmService.updateById(requestBean.getData())) {
			return responseSuccess();
		} else {
			return responseFail();
		}
	}

	@ApiOperation(value = "删除")
	@RequiresPermissions("002000100020")
	@PostMapping("/remove")
	public ResponseBean delete(@RequestBody RequestBean requestBean) {
		List ids = (List) requestBean.getParam().get("ids");
		if (iOrderitmService.removeByIds(ids)) {
			return responseSuccess();
		} else {
			return responseFail();
		}
	}
}
